package com.dili.dd.gpi.util.spring;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zhaoYuan on 2015/4/9.
 */
public class ValidatorResultUtil {

    /**
     * 后去全部错误消息
     * @param result
     * @return
     */
    public static List<String> getErrorMessages(BindingResult result){
        List<String> messages = new LinkedList<>();
        if(messages != null){
            List<ObjectError> allErrors = result.getAllErrors();
            for (ObjectError error : allErrors) {
                messages.add(error.getDefaultMessage());
            }
        }
        return messages;
    }
}
